package mornd.beannameurl;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: mornd
 * @dateTime: 2023/5/9 - 16:35
 * 必须实现 Controller 接口
 */
@Component("/c1")
public class Controller1 implements Controller {
    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.getWriter().print("this is c1");
        return null;
    }

    @Bean("/c2")
    public Controller controller3() {
        return (request, response) -> {
            response.getWriter().print("this is c2");
            return null;
        };
    }
}

@Component("/c3")
class Controller3 implements Controller {
    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.getWriter().print("this is c3");
        return null;
    }
}
